<?php
/*
 *                        _oo0oo_
 *                       o8888888o
 *                       88" . "88
 *                       (| -_- |)
 *                       0\  =  /0
 *                     ___/`---'\___
 *                   .' \\|     |// '.
 *                  / \\|||  :  |||// \
 *                 / _||||| -:- |||||- \
 *                |   | \\\  - /// |   |
 *                | \_|  ''\---/''  |_/ |
 *                \  .-\__  '-'  ___/-. /
 *              ___'. .'  /--.--\  `. .'___
 *           ."" '<  `.___\_<|>_/___.' >' "".
 *          | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *          \  \ `_.   \_ __\ /__ _/   .-` /  /
 *      =====`-.____`.___ \_____/___.-`___.-'=====
 *                        `=---='
 * 
 * 
 *      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 * 
 *            佛祖保佑       永不宕机     永无BUG
 */
/*
 * 用户操作页
 * @Author: LD
 * @Date: 2021-03-04 18:16:55
 * @LastEditors: LD
 * @LastEditTime: 2021-03-04 18:39:06
 * @Description: file content
 * @FilePath: \gongchengqiaojob\Application\Home\Controller\PcUserapiController.class.php
 */
namespace Home\Controller;
use Common\Controller\PcApiController;
use Common\ORG\PublicFunction;
use Common\ORG\WxFunction;
use Think\Db;

class PcMembersController extends PcApiController{

	public function _initialize() {
        
        $getsecret  = $_SERVER['HTTP_APPSECRET'];
        //取head标签内容
        if(!preg_match('/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/', $getsecret)){
            $this->ajaxReturn(1, 'appsecret格式错误');
        }

        if($this->appsecret <> $getsecret){
            $this->ajaxReturn(1, 'appsecret错误');
        }
        parent::_initialize();
    }

    /**
     * getBasicInfo
     * 获取用户资料

     * 获取用户基础信息资料

     * @access public

     * @since

     * @return json

     */
    public function getBasicInfo(){
        $id     = I('post.id', 0,'intval');//查询指定用户信息
        $uid    = I('post.uid', 0,'intval');//查询指定用户信息

        if(empty($id) && empty($uid) ) $this->ajaxReturn(1,'参数错误');

        $where  = !empty($uid) ? ['uid' => $uid] : ['id' => $id];
        $resume = M('Resume')->where($where)->find();
        $user   = M('Members')->where(['uid'=> $resume['uid']])->find();

        if(empty($resume)) $this->ajaxReturn(1,'用户简历信息不存在');

        $is_show=I('is_show',0);// 是否显示  用户主动投递的就直接显示

        if(empty($user)) $this->ajaxReturn(1,'用户注册信息不存在');


        $political  = D('Category')->get_category_cache()['QS_political'];//政治面貌
        $trade      = D('CategoryMajor')->get_major_list();//工程分类
        $nature     = D('Category')->get_category_cache()['QS_dutytime'];//到岗时间
        $jobTag     = D('Category')->get_category_cache()['QS_jobtag'];//期望福利

        //获取全部职位类别
        $jobs       = explode(',', $resume['jobs_id']);
        $jobsName   = [];
        foreach($jobs as $val){
            $job_t      = explode('.', $val);
            $jid        = !empty($job_t[1]) ? $job_t[1] : $job_t[0];
            $jobsName[] = !empty(D('CategoryJobs')->getJobsName($jid)) ? D('CategoryJobs')->getJobsName($jid) : '';
        }

        //设置简历已查看
        if(C('pcvisitor.utype') == 1){
            $view_log = M('ViewResume')->where(array('uid'=>C('pcvisitor.uid'),'resumeid'=>$resume['id']))->find();
            if($view_log){
                M('ViewResume')->where(array('uid'=>C('pcvisitor.uid'),'resumeid'=>$resume['id']))->setField('addtime',time());
            }else{
                M('ViewResume')->add(array('uid'=>C('pcvisitor.uid'),'resumeid'=>$resume['id'],'resume_uid'=>$resume['uid'],'addtime'=>time()));
            }
            // if($_GET['jobs_id']){
            $apply_log = D('PersonalJobsApply')->check_jobs_apply($resume['id'],C('pcvisitor.uid'),intval($_GET['jobs_id']));
            $apply_log && D('PersonalJobsApply')->set_apply($apply_log,C('pcvisitor'),2);
            // }
        }


        //获取上传图片
        $imgs   = M("ResumeImg")->where(['uid'=>$user['uid'], 'resume_id'=> $resume['id'], 'audit'=>['in', [1,2]]])->select();
        foreach($imgs as &$item){
            $item['addtime']    = date('Y-m-d H:i:s', $item['addtime']);
            $item['img']        = C('qscms_site_domain') . __ROOT__ . '/data/upload/resume_img/'.$item['img'];
            unset($item['title'],$item['audit']);
        }

        //教育经历
        $educationList      = D('ResumeEducation')->get_resume_education($resume['id'], $user['uid']);
        $educationListNew   = [];
        foreach($educationList as &$val){
            $educationListNew[] = [
                "id"            => $val['id'],
                "pid"           => $val['pid'],
                "uid"           => $val['uid'],
                "school"        => $val['school'],
                "speciality"    => $val['speciality'],
                "education"     => $val['education'],
                "education_cn"  => $val['education_cn'],
                "start_date"    => $val['startyear'].'-'.str_pad($val['startmonth'],2,"0",STR_PAD_LEFT),
                "end_date"      => $val['endyear'].'-'.str_pad($val['endmonth'],2,"0",STR_PAD_LEFT),
            ];
        }
        unset($educationList);

        //工作单位项目经历

        $workList       = D('ResumeWork')->get_resume_work($resume['id'], $user['uid']);
        $workListNew    = [];
        foreach($workList as &$valw){
            $workListNew[] = [
                "id"            => $valw['id'],
                "pid"           => $valw['pid'],
                "uid"           => $valw['uid'],
                "companyname"   => $valw['companyname'],
                "jobs"          => $valw['jobs'],
                "achievements"  => $valw['achievements'],
                "address"       => $valw['address'],
                "start_date"    => $valw['startyear'].'-'.str_pad($valw['startmonth'],2,"0",STR_PAD_LEFT),
                "end_date"      => $valw['endyear'].'-'.str_pad($valw['endmonth'],2,"0",STR_PAD_LEFT),
            ];
        }
        unset($workList);

        //资格证书
        $credentList   = D('ResumeCredent')->get_resume_credent($resume['id'], $user['uid']);
        foreach($credentList as &$valc){
            $valc['year_month']  = $valc['year'].'-'.$valc['month'];
            unset($valc['year'],$valc['month'], $valc['images']);
        }

        //是否下载
        $down   = M("CompanyDownResume")->where(['resume_id'=>$resume['id'], 'company_uid'=>$this->userinfo['uid']])->find();

        //人才顾问判断是否问答通过
        //if($user['utype']==0) {
        $wenda = M('questionnaire_user_list')->where(['uid' => $user['uid']])->order('id desc')->find();
        //}

        //是否支付
        //$order  = M('Order')->where(['uid'=>$user['uid'], 'order_type'=>17, 'is_paid'=>2])->find();

        //获取擅长职位类别名称
        $goodJobsCn = [];
        if($resume['good_jobs']) {
            $gjarr  = explode(',', $resume['good_jobs']);
            foreach($gjarr as $jval) {
                $gj_t   = explode('.', $jval);
                $gjid   = !empty($gj_t[1]) ? $gj_t[1] : $gj_t[0];
                $goodJobsCn[]   = !empty(D('CategoryJobs')->getJobsName($gjid)) ? D('CategoryJobs')->getJobsName($gjid) : '';
            }
        }

        //获取擅长工程类别
        $goodTradeCn    = [];
        if($resume['good_trade']) {
            $gtarr      = explode(',', $resume['good_trade']);
            foreach($gtarr as $tval) {
                $t              = explode('.', $tval);
                $goodTradeCn[]  = !empty($t[1]) && !empty($trade[$t[1]]) ? $trade[$t[1]]['categoryname'] : (!empty($t[0]) && !empty($trade[$t[0]]) ? $trade[$t[0]]['categoryname'] : '');
            }
        }

        //期望福利
        $jobTagCn   = [];
        if($resume['job_tag']){
            $jtarr  =explode(',', $resume['job_tag']);
            foreach($jtarr as $jval) {
                $jobTagCn[]  = !empty($jobTag[$jval]) ? $jobTag[$jval] : '';
            }
        }

        $data   = [
            'id'            => $resume['id'],
            'avatars'       => avatar($user['uid']),
            'utype'         => $user['utype'],
            'advisor_level' => $user['advisor_level'] ? $user['advisor_level'] : '0', //顾问等级
            'advisor_level_name' => $user['advisor_level_name'] ? $user['advisor_level_name'] : '', //顾问等级名称
            'display'       => $resume['display'],  //简历可见权限 0都可见 1招聘方可见 2人才顾问可见
            'audit'         => $resume['audit'],
            'status'        => !empty($wenda) ? $wenda['status'] : '3',
            //'order_status'  => !empty($order) ? '1' : '0',
            'sex'           => $resume['sex'],      //性别
            'sex_cn'        => $resume['sex_cn'],   //性别明文
            'marriage'      => $resume['marriage'], //婚姻状态
            'marriage_cn'   => $resume['marriage_cn'],//婚姻状态明文
            'skill'         => $resume['skill'],    //特殊技能特长
          //  'fullname'      => $resume['fullname'], //姓名
            'birthdate'     => $resume['birthdate'],//出生年月
            'age'           => birthdayToAge($resume['birthdate']),//年龄
            'first_work_date'       => $resume['first_work_date'], //首次工作日期
            'householdaddress'      => $resume['householdaddress'], //籍贯户籍地
            'householdaddress_cn'   => D('CategoryDistrict')->getCityName($resume['householdaddress']),//籍贯户籍地明文
            'residence'     => !empty($resume['residence']) ? $resume['residence'] : '', //居住地
            'residence_cn'  => !empty($resume['residence']) ? D('CategoryDistrict')->getCityName($resume['residence']) : '', //居住地明文
//            'telephone'     => !empty($down) || (empty($uid) && empty($id)) || $is_show ? $resume['telephone'] : contact_hide($resume['telephone'],2),
//            'email'         => !empty($down) || (empty($uid) && empty($id)) || $is_show ? $resume['email'] : contact_hide($resume['email'],3),
            'telephone'     => !empty($down)  || $is_show ? $resume['telephone'] : '****',
            'email'         => !empty($down)  || $is_show ? $resume['email'] : '****',
            'fullname'         => !empty($down)  || $is_show ? $resume['fullname'] :  contact_hide($resume['fullname'], -2),
            'country'       => $resume['country'],  //国籍
            'political'     => $resume['political'],//政治面貌
            'political_cn'  => !empty($political[$resume['political']]) ? $political[$resume['political']] : '',//政治面貌明文
            'year_income'   => $resume['year_income'],//年收入
            'level'         => $resume['level'], //简历完整度级别 1差 2良 3优
            'complete_percent'=> $resume['complete_percent'], //简历完整度%
            'stime'         => date('Y-m-d H:i:s', $resume['stime']),//保存时间
            'refreshtime'   => date('Y-m-d H:i:s', $resume['refreshtime']),//刷新时间
            'addtime'       => date('Y-m-d H:i:s', $resume['addtime']),//添加时间

            //自我描述
            'specialty'     => $resume['specialty'],//自我描述
            'good_trade'    => $resume['good_trade'],//擅长工程类别
            'good_trade_cn' => $goodTradeCn,//擅长工程明文
            'good_jobs'     => $resume['good_jobs'],//擅长职位类别
            'good_jobs_cn'  => $goodJobsCn,//擅长职位明文

            //求职信息
            'intention_jobs_id'     => $resume['intention_jobs_id'],//意向职位
            'intention_jobs'        => explode(',', $resume['intention_jobs']),//意向职位明文
            'jobs_id'               => !empty($resume['jobs_id']) ? $resume['jobs_id'] : '',//职位类别ID
            'jobs_id_cn'            => !empty($resume['jobs_id']) ? $jobsName : '',//职位类别明文
            'trade'                 => $resume['trade'],//工程类别
            'trade_cn'              => explode(',', $resume['trade_cn']),//工程类别明文
            'district'              => !empty($resume['district']) ? $resume['district'] : '',//期望工作地点
            'district_cn'           => !empty($resume['district']) ? explode(',', $resume['district_cn']) : '',//期望工作地点明文
            'wage'                  => $resume['wage'],//薪资范围
            'wage_cn'               => $resume['wage_cn'],//薪资范围明文
            'nature'                => $resume['nature'],//期望工作性质
            'nature_cn'             => $resume['nature_cn'],//期望工作性质明文
            'current'               => $resume['current'],//求职状态
            'current_cn'            => $resume['current_cn'],//求职状态明文
            'duty_time'             => $resume['duty_time'],//期望到岗时间
            'duty_time_cn'          => !empty($nature[$resume['duty_time']]) ? $nature[$resume['duty_time']] : '',//期望到岗时间明文
            'job_tag'               => $resume['job_tag'],//期望福利
            'job_tag_cn'            => $jobTagCn,//期望福利

            //是否下载简历
            'down'                  => empty($down) ? '0' : '1',

            //教育经历
            'educationList' => $educationListNew,

            //工作单位/项目经历
            'workList'      => $workListNew,

            //语言能力
            'languageList'  => D('ResumeLanguage')->get_resume_language($resume['id'], $user['uid']),

            //资格证书
            'credentList'   => $credentList,

            //
            //上传文件类型
            'word'          => [
                'word_resume'           => !empty($resume['word_resume']) ? C('qscms_site_domain') . __ROOT__ . '/data/upload/word_resume/'.$resume['word_resume'] : '',
                'word_resume_title'     => $resume['word_resume_title'],
                'word_resume_addtime'   => !empty($resume['word_resume_title']) ? date('Y-m-d H:i:s', $resume['word_resume_title']) : '',
            ], //简历附件
            'other_word'          => [
                'other_word_resume'           => !empty($resume['other_word_resume']) ? C('qscms_site_domain') . __ROOT__ . '/data/upload/other_word_resume/'.$resume['other_word_resume'] : '',
                'other_word_resume_title'     => $resume['other_word_resume_title'],
                'other_word_resume_addtime'   => !empty($resume['other_word_resume_addtime']) ? date('Y-m-d H:i:s', $resume['other_word_resume_addtime']) : '',
            ], //其他简历附件
            'video'         => [
                'resume_video'           => !empty($resume['resume_video']) ? C('qscms_site_domain') . __ROOT__ . '/data/upload/resume_video/'.$resume['resume_video'] : '',
                'resume_video_title'     => $resume['resume_video_title'],
                'resume_video_addtime'   => !empty($resume['resume_video_addtime']) ? date('Y-m-d H:i:s', $resume['resume_video_addtime']) : '',
            ], //视频文件
            'resume_img'    => $imgs,//上传图片集合

        ];

        $this->ajaxReturn(0, 'ok', $data);

    }

}
?>